<!-- 我的弹窗 -->

<template>
  <WebModal small>
    <WebForm>
      <FormSelect v-bind="groupProps" />

      <FormSelect v-bind="subGroupProps" />

      <FormRadio label="通知类型" bind="noticeType" :dict="DICT.NOTICE" initFirst required />

      <EasyRow v-if="one.noticeType === 2" col2>
        <FormSelect v-bind="typeProps" />
        <FormSelect v-bind="subTypeProps" word2 />
      </EasyRow>

      <FormSlot label="通知人" bind="processDto" tip="请选择通知人" required>
        <ModalUser />
      </FormSlot>

      <FormStatus label="状态" isRadio />
    </WebForm>
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import MyModal from '@admin/views/Maintain/Repair/RepairTemplate/MyModal'

// ============================== 导出组件 ============================== //

export default CORE.extend(MyModal, {
  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    ...MyModal.computed,

    /**
     * 分组属性
     */
    groupProps() {
      const dict = this.$root.alarm_group_treeDict.map(([, ...other]) => other)
      return {
        label: `${CORE.MAP.ALARM}系统`,
        bind: 'subSystemId, subSystemName, subSystemCode',
        dict,
        required: true,
      }
    },

    /**
     * 子分组属性
     */
    subGroupProps() {
      const { $root: { alarm_group_treeDict: groupDict }, MAP: { ALL }, one: { subSystemId } } = this
      const matched = groupDict.find((item) => item[1] === subSystemId) || []
      const dict = (matched[0] || []).map(([, ...other]) => other)
      return {
        label: `${CORE.MAP.ALARM}类型`,
        bind: 'alarmTypeId, alarmTypeName, alarmTypeCode',
        dict: subSystemId ? [ALL, ...dict] : [],
        required: true,
      }
    },
  },
})
</script>
